package com.qf.shopping.service.carService.impl;

import com.qf.shopping.mapper.carMapper.CarMakeMapper;
import com.qf.shopping.mapper.carMapper.CarModelMapper;
import com.qf.shopping.pojo.car.CarMake;
import com.qf.shopping.pojo.car.CarModel;
import com.qf.shopping.service.carService.ICarModelService;
import com.qf.shopping.vo.carVO.CarModelConstom;
import com.qf.shopping.vo.carVO.CarModelVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author Humy
 * @date 2019/4/18 20:37
 */

@Service
@Transactional
public class CarModelServiceImpl implements ICarModelService {

    @Resource
    private CarModelMapper carModelMapper = null;

    @Resource
    private CarMakeMapper carMakeMapper = null;

    @Override
    public void add(CarModel carModel) {
        System.out.println("carModelVO是+++++++++++"+carModel);
//        CarModelConstom carModelConstom = carModel.getCarModelConstom();
//        System.out.println("carModelConstom是+++++++++++"+carModelConstom);
        //通过品牌id获取品牌的对象
//        CarMake carMake = carMakeMapper.findCarMakeByMakeId(carModelConstom.getMakeId());
//        carModelConstom.setBrandId(carMake.getBrandId());//设置品牌id
//        carModelConstom.setBrandName(carMake.getBrandName());//设置品牌名字
//        carModelConstom.setCountryId(carMake.getCountryId());//设置国家id

        //生成创建时间
        Date date1 = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String string = dateFormat.format(date1);
        Long date = Long.valueOf(string);
        carModel.setCreateTime(date);

//        carModel.setCarModelConstom(carModelConstom);
        carModelMapper.insert(carModel);

    }


    /**
     * 根据查询条件查询
     * @param carModel
     * @return
     */
    @Override
    public List<CarModel> query(CarModel carModel) {

        List<CarModel> carModels = carModelMapper.findCarModel(carModel);

        return carModels;
    }


    /**
     *新增车款时，根据品牌id查询车系
     * @param makeId
     * @return
     */
    @Override
    public List<CarModel> queryByMakeId(Long makeId) {

        List<CarModel> carModels = carModelMapper.findCarModelByMakeId(makeId);
        return carModels;
    }


    /**
     * 查询所有车系
     * @return
     */
    @Override
    public List<CarModel> queryAllCarModel() {

        List<CarModel> carModels = carModelMapper.findAllCarModel();
        return carModels;
    }

    /**
     * 根据车系id查询车系
     * @param id
     * @return
     */
    @Override
    public CarModel queryCarModel(Long id) {

        CarModel carModel = carModelMapper.findCarModelById(id);

        return carModel;
    }


    /**
     * 修改车系
     * @param carModel
     */
    @Override
    public void update(CarModel carModel) {

        carModelMapper.updateCarModel(carModel);

    }

    /**
     * 删除车系
     * @param ids
     */
    @Override
    public void delete(Long... ids) {

        carModelMapper.deleteCarModel(ids);

    }



}
